﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;


namespace Metex
{
    public class PatternMatcher
    {
        public string Pattern { get; set; }
        private IToken token;
        public IToken Token
        {
            get
            {
                return token.Clone();
            }
        }
        public PatternMatcher(string pattern, IToken token)
        {
            this.Pattern = pattern;
            this.token = token;
        }
        public bool TryMatch(string input)
        {
            Match m = Regex.Match(input, Pattern);
            if (m.Success)
            {
                token.Lexeme = m.Groups[0].Value;
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}
